<?php
declare (strict_types=1);

namespace app\service;

use app\model\TSkuParam;
use app\traits\ServiceTrait;
use think\facade\Db;

/**
 * sku
 * Class TSkuParamService
 * @package app\service
 */
class TSkuParamService
{
    //模型，带命名空间
    public static $model = 'app\model\TSkuParam';
    //模型主键
    public static $pk = 'id';
    //name字段名称
    public static $name = 'group_name';

    use ServiceTrait;

    /**
     * @param $type
     * @return array
     */
    public static function getSku($type)
    {
        // 列表
        $table = TSkuParam::$_table;
        $r = Db::table($table)->where(['type' => $type])->select();
        if (empty($r)) {
            return [];
        }

        $groupData = [];
        foreach ($r as $v) {
            $groupData[$v['group_id']]['checkValue'] = '';
            $groupData[$v['group_id']]['id'] = $v['id'];
            $groupData[$v['group_id']]['labels'] = '';
            $groupData[$v['group_id']]['name'] = $v['group_name'];
            $groupData[$v['group_id']]['params'] = '';
            $groupData[$v['group_id']]['skuParams'][] = [
                'code' => $v['code'],
                'createTime' => '',
                'groupId' => $v['group_id'],
                'groupName' => $v['group_name'],
                'id' => $v['id'],
                'name' => $v['name'],
                'remark' => '',
                'sortNo' => $v['sort_no'],
                'type' => $v['type'],
                'updateTime' => '',
            ];
        }
        return array_values($groupData);
    }
}
